ABAP Select data from SAP table ISPAYMENTADVICETP into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP ISPAYMENTADVICETP table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to ISPAYMENTADVICETP. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the ISPAYMENTADVICETP table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_ISPAYMENTADVICETP TYPE STANDARD TABLE OF ISPAYMENTADVICETP,
      WA_ISPAYMENTADVICETP TYPE ISPAYMENTADVICETP,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: <ISPAYMENTADVICETP> TYPE ISPAYMENTADVICETP.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_ISPAYMENTADVICETP.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM ISPAYMENTADVICETP
  INTO TABLE IT_ISPAYMENTADVICETP.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM ISPAYMENTADVICETP
*  INTO TABLE @DATA(IT_ISPAYMENTADVICETP2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_ISPAYMENTADVICETP INDEX 1 INTO DATA(WA_ISPAYMENTADVICETP2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_ISPAYMENTADVICETP ASSIGNING <ISPAYMENTADVICETP>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<ISPAYMENTADVICETP>-KEY = 1.
<ISPAYMENTADVICETP>-PARENT_KEY = 1.
<ISPAYMENTADVICETP>-ROOT_KEY = 1.
<ISPAYMENTADVICETP>-COMPANYCODE = 1.
<ISPAYMENTADVICETP>-PAYMENTADVICEACCOUNTTYPE = 1.
ENDLOOP.

LOOP AT IT_ISPAYMENTADVICETP INTO WA_ISPAYMENTADVICETP.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_ISPAYMENTADVICETP-PAYMENTADVICEACCOUNT, sy-vline,
WA_ISPAYMENTADVICETP-PAYMENTADVICE, sy-vline,
WA_ISPAYMENTADVICETP-COMPANYCODEFOREDIT, sy-vline,
WA_ISPAYMENTADVICETP-PAYTADVICEACCOUNTTYPEFOREDIT, sy-vline,
WA_ISPAYMENTADVICETP-PAYMENTADVICEACCOUNTFOREDIT, sy-vline,
WA_ISPAYMENTADVICETP-PAYMENTADVICEFOREDIT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ISPAYMENTADVICETP you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_ISPAYMENTADVICETP TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_ISPAYMENTADVICETP INTO WA_ISPAYMENTADVICETP. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.

*Conversion exit ALPHA, internal->external for field PAYMENTADVICEACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISPAYMENTADVICETP-PAYMENTADVICEACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISPAYMENTADVICETP-PAYMENTADVICEACCOUNT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PAYMENTADVICEACCOUNTFOREDIT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISPAYMENTADVICETP-PAYMENTADVICEACCOUNTFOREDIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISPAYMENTADVICETP-PAYMENTADVICEACCOUNTFOREDIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PAYMENTDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISPAYMENTADVICETP-PAYMENTDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISPAYMENTADVICETP-PAYMENTDOCUMENT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit AC132, internal->external for field PAIDAMOUNTINPAYTCURRENCY CALL FUNCTION 'CONVERSION_EXIT_AC132_OUTPUT' EXPORTING input = WA_ISPAYMENTADVICETP-PAIDAMOUNTINPAYTCURRENCY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISPAYMENTADVICETP-PAIDAMOUNTINPAYTCURRENCY.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CUSTOMER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ISPAYMENTADVICETP-CUSTOMER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISPAYMENTADVICETP-CUSTOMER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit AC132, internal->external for field PAYMENTADVICEITEMTOTALAMOUNT CALL FUNCTION 'CONVERSION_EXIT_AC132_OUTPUT' EXPORTING input = WA_ISPAYMENTADVICETP-PAYMENTADVICEITEMTOTALAMOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ISPAYMENTADVICETP-PAYMENTADVICEITEMTOTALAMOUNT.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_ISPAYMENTADVICETP_STR,
KEY TYPE STRING,
PARENT_KEY TYPE STRING,
ROOT_KEY TYPE STRING,
COMPANYCODE TYPE STRING,
PAYMENTADVICEACCOUNTTYPE TYPE STRING,
PAYMENTADVICEACCOUNT TYPE STRING,
PAYMENTADVICE TYPE STRING,
COMPANYCODEFOREDIT TYPE STRING,
PAYTADVICEACCOUNTTYPEFOREDIT TYPE STRING,
PAYMENTADVICEACCOUNTFOREDIT TYPE STRING,
PAYMENTADVICEFOREDIT TYPE STRING,
PAYMENTDOCUMENT TYPE STRING,
ACCOUNTBYSHIPPER TYPE STRING,
PAYMENTCURRENCY TYPE STRING,
PAYMENTDATE TYPE STRING,
PAIDAMOUNTINPAYTCURRENCY TYPE STRING,
CASHDISCOUNTAMOUNTINPAYTCRCY TYPE STRING,
PARTNERBANKCOUNTRY TYPE STRING,
PARTNERBANKSWIFTCODE TYPE STRING,
CREATEDBYUSER TYPE STRING,
CREATIONDATE TYPE STRING,
LASTCHANGEDATE TYPE STRING,
LASTCHANGEDBYUSER TYPE STRING,
PAYMENTADVICEHEADERTEXT TYPE STRING,
PAYMENTADVICETYPE TYPE STRING,
PAYMENTADVICETYPENAME TYPE STRING,
CREATIONTIME TYPE STRING,
PAYMENTADVICESTATUS TYPE STRING,
PAYTADVCDIFFDETERMINATIONRULE TYPE STRING,
PAYTADVCDIFFDETNRULEDESC TYPE STRING,
PAYMENTADVICESELECTIONRULE TYPE STRING,
PAYTADVICESELECTIONRULEDESC TYPE STRING,
ORIGINALREFERENCEDOCUMENT TYPE STRING,
CUSTOMERNAME TYPE STRING,
FULLNAME TYPE STRING,
ORGANIZATIONBPNAME1 TYPE STRING,
ORGANIZATIONBPNAME2 TYPE STRING,
COMPANYCODENAME TYPE STRING,
PAYMENTADVICEISEXTRACTED TYPE STRING,
PAYTADVICEEXTRACTORCONFIDENCE TYPE STRING,
PAYMENTADVICEEXTRACTORUUID TYPE STRING,
PAYMENTADVICEUUID TYPE STRING,
PAYMENTADVICEEXTRACTIONSTATUS TYPE STRING,
PAYTADVICETOTALNUMBEROFPAGES TYPE STRING,
UXFCPAYMENTADVICEACCOUNT TYPE STRING,
ACCOUNTINGCLERK TYPE STRING,
ACCOUNTINGCLERKNAME TYPE STRING,
CUSTOMER TYPE STRING,
PAYMENTADVICEITEMTOTALAMOUNT TYPE STRING,
BANKREFERENCE TYPE STRING,
BUSINESSPARTNERNAME TYPE STRING,
HASACTIVEENTITY TYPE STRING,
DRAFTENTITYCREATIONDATETIME TYPE STRING,
DRAFTENTITYLASTCHANGEDATETIME TYPE STRING,
DRAFTADMINISTRATIVEDATAUUID TYPE STRING,
DRAFTENTITYCONSISTENCYSTATUS TYPE STRING,
DRAFTENTITYOPERATIONCODE TYPE STRING,
ISACTIVEENTITY TYPE STRING,END OF T_EKKO_STR. DATA: WA_ISPAYMENTADVICETP_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_ISPAYMENTADVICETP_STR-KEY sy-vline
WA_ISPAYMENTADVICETP_STR-PARENT_KEY sy-vline
WA_ISPAYMENTADVICETP_STR-ROOT_KEY sy-vline
WA_ISPAYMENTADVICETP_STR-COMPANYCODE sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEACCOUNTTYPE sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEACCOUNT sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICE sy-vline
WA_ISPAYMENTADVICETP_STR-COMPANYCODEFOREDIT sy-vline
WA_ISPAYMENTADVICETP_STR-PAYTADVICEACCOUNTTYPEFOREDIT sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEACCOUNTFOREDIT sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEFOREDIT sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTDOCUMENT sy-vline
WA_ISPAYMENTADVICETP_STR-ACCOUNTBYSHIPPER sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTCURRENCY sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTDATE sy-vline
WA_ISPAYMENTADVICETP_STR-PAIDAMOUNTINPAYTCURRENCY sy-vline
WA_ISPAYMENTADVICETP_STR-CASHDISCOUNTAMOUNTINPAYTCRCY sy-vline
WA_ISPAYMENTADVICETP_STR-PARTNERBANKCOUNTRY sy-vline
WA_ISPAYMENTADVICETP_STR-PARTNERBANKSWIFTCODE sy-vline
WA_ISPAYMENTADVICETP_STR-CREATEDBYUSER sy-vline
WA_ISPAYMENTADVICETP_STR-CREATIONDATE sy-vline
WA_ISPAYMENTADVICETP_STR-LASTCHANGEDATE sy-vline
WA_ISPAYMENTADVICETP_STR-LASTCHANGEDBYUSER sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEHEADERTEXT sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICETYPE sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICETYPENAME sy-vline
WA_ISPAYMENTADVICETP_STR-CREATIONTIME sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICESTATUS sy-vline
WA_ISPAYMENTADVICETP_STR-PAYTADVCDIFFDETERMINATIONRULE sy-vline
WA_ISPAYMENTADVICETP_STR-PAYTADVCDIFFDETNRULEDESC sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICESELECTIONRULE sy-vline
WA_ISPAYMENTADVICETP_STR-PAYTADVICESELECTIONRULEDESC sy-vline
WA_ISPAYMENTADVICETP_STR-ORIGINALREFERENCEDOCUMENT sy-vline
WA_ISPAYMENTADVICETP_STR-CUSTOMERNAME sy-vline
WA_ISPAYMENTADVICETP_STR-FULLNAME sy-vline
WA_ISPAYMENTADVICETP_STR-ORGANIZATIONBPNAME1 sy-vline
WA_ISPAYMENTADVICETP_STR-ORGANIZATIONBPNAME2 sy-vline
WA_ISPAYMENTADVICETP_STR-COMPANYCODENAME sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEISEXTRACTED sy-vline
WA_ISPAYMENTADVICETP_STR-PAYTADVICEEXTRACTORCONFIDENCE sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEEXTRACTORUUID sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEUUID sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEEXTRACTIONSTATUS sy-vline
WA_ISPAYMENTADVICETP_STR-PAYTADVICETOTALNUMBEROFPAGES sy-vline
WA_ISPAYMENTADVICETP_STR-UXFCPAYMENTADVICEACCOUNT sy-vline
WA_ISPAYMENTADVICETP_STR-ACCOUNTINGCLERK sy-vline
WA_ISPAYMENTADVICETP_STR-ACCOUNTINGCLERKNAME sy-vline
WA_ISPAYMENTADVICETP_STR-CUSTOMER sy-vline
WA_ISPAYMENTADVICETP_STR-PAYMENTADVICEITEMTOTALAMOUNT sy-vline
WA_ISPAYMENTADVICETP_STR-BANKREFERENCE sy-vline
WA_ISPAYMENTADVICETP_STR-BUSINESSPARTNERNAME sy-vline
WA_ISPAYMENTADVICETP_STR-HASACTIVEENTITY sy-vline
WA_ISPAYMENTADVICETP_STR-DRAFTENTITYCREATIONDATETIME sy-vline
WA_ISPAYMENTADVICETP_STR-DRAFTENTITYLASTCHANGEDATETIME sy-vline
WA_ISPAYMENTADVICETP_STR-DRAFTADMINISTRATIVEDATAUUID sy-vline
WA_ISPAYMENTADVICETP_STR-DRAFTENTITYCONSISTENCYSTATUS sy-vline
WA_ISPAYMENTADVICETP_STR-DRAFTENTITYOPERATIONCODE sy-vline
WA_ISPAYMENTADVICETP_STR-ISACTIVEENTITY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.