ABAP Select data from SAP table /PRA/S_BP_VENDOR_MD 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 /PRA/S_BP_VENDOR_MD 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 /PRA/S_BP_VENDOR_MD. 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 /PRA/S_BP_VENDOR_MD 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_/PRA/S_BP_VENDOR_MD TYPE STANDARD TABLE OF /PRA/S_BP_VENDOR_MD,
      WA_/PRA/S_BP_VENDOR_MD TYPE /PRA/S_BP_VENDOR_MD,
      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: </PRA/S_BP_VENDOR_MD> TYPE /PRA/S_BP_VENDOR_MD.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /PRA/S_BP_VENDOR_MD
  INTO TABLE IT_/PRA/S_BP_VENDOR_MD.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /PRA/S_BP_VENDOR_MD
*  INTO TABLE @DATA(IT_/PRA/S_BP_VENDOR_MD2).
*--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_/PRA/S_BP_VENDOR_MD INDEX 1 INTO DATA(WA_/PRA/S_BP_VENDOR_MD2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/PRA/S_BP_VENDOR_MD ASSIGNING </PRA/S_BP_VENDOR_MD>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</PRA/S_BP_VENDOR_MD>-SENDER_TECHNICAL_ID = 1.
</PRA/S_BP_VENDOR_MD>-VENDID = 1.
</PRA/S_BP_VENDOR_MD>-INTERCOCD = 1.
</PRA/S_BP_VENDOR_MD>-PARTNERROLE = 1.
</PRA/S_BP_VENDOR_MD>-ENTY_CD = 1.
ENDLOOP.

LOOP AT IT_/PRA/S_BP_VENDOR_MD INTO WA_/PRA/S_BP_VENDOR_MD.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/PRA/S_BP_VENDOR_MD-DIRECT_PAY_FL, sy-vline,
WA_/PRA/S_BP_VENDOR_MD-DO_NOT_RPT_ONRR, sy-vline,
WA_/PRA/S_BP_VENDOR_MD-OWNER_MIN_PAY, sy-vline,
WA_/PRA/S_BP_VENDOR_MD-PAY_FREQUENCY, sy-vline,
WA_/PRA/S_BP_VENDOR_MD-DO_NOT_RECOUP, sy-vline,
WA_/PRA/S_BP_VENDOR_MD-PAYMENT_TYPE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/PRA/S_BP_VENDOR_MD 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_/PRA/S_BP_VENDOR_MD 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_/PRA/S_BP_VENDOR_MD INTO WA_/PRA/S_BP_VENDOR_MD. *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 VENDID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PRA/S_BP_VENDOR_MD-VENDID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PRA/S_BP_VENDOR_MD-VENDID.
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_/PRA/S_BP_VENDOR_MD_STR,
SENDER_TECHNICAL_ID TYPE STRING,
VENDID TYPE STRING,
INTERCOCD TYPE STRING,
PARTNERROLE TYPE STRING,
ENTY_CD TYPE STRING,
DIRECT_PAY_FL TYPE STRING,
DO_NOT_RPT_ONRR TYPE STRING,
OWNER_MIN_PAY TYPE STRING,
PAY_FREQUENCY TYPE STRING,
DO_NOT_RECOUP TYPE STRING,
PAYMENT_TYPE TYPE STRING,
NO_CHECK_STMT TYPE STRING,
LEVY TYPE STRING,
KGLND TYPE STRING,
CDEX_COMPANY TYPE STRING,
TRIBE_NO TYPE STRING,
BACKUP_WITHHOLD TYPE STRING,
KGREG TYPE STRING,
TAX_ID_TYPE TYPE STRING,
RECOUP_PC TYPE STRING,
RECIP_CODE_1042S TYPE STRING,
TIN_MATCH_DATE TYPE STRING,
TIN_RESP_DATE TYPE STRING,
TIN_W8 TYPE STRING,
TIN_W9 TYPE STRING,
TIN_OTHERS TYPE STRING,
BN1_DATE TYPE STRING,
BN1_RESP_DATE TYPE STRING,
BN1_W8 TYPE STRING,
BN1_W9 TYPE STRING,
BN1_OTHERS TYPE STRING,
BN2_DATE TYPE STRING,
IRS_RESP_DATE TYPE STRING,
FLAG_1099 TYPE STRING,
FLAG_NRA TYPE STRING,
REP_ENTITY_TYPE TYPE STRING,
NAME_ID TYPE STRING,
OWNER_NM_LAST TYPE STRING,
OWNER_NM_FIRST TYPE STRING,
OWNER_NM_MIDDLE TYPE STRING,
OWNER_NM_PREFIX TYPE STRING,
OWNER_NM_SUFFIX TYPE STRING,
OWNER_NM_TITLE TYPE STRING,
OWNER_ADDRESS1 TYPE STRING,
OWNER_ADDRESS2 TYPE STRING,
OWNER_ADDRESS3 TYPE STRING,
OWNER_CITY TYPE STRING,
OWNER_COUNTY TYPE STRING,
OWNER_STATE TYPE STRING,
OWNER_ZIP TYPE STRING,
OWNER_COUNTRY TYPE STRING,
OWNER_TAXID TYPE STRING,
OWNER_TAXID_EXT TYPE STRING,
OWNER_DOB TYPE STRING,
T_RCPMNTINFO TYPE STRING,
T_SPHNDLCODES TYPE STRING,
T_EXWHTINFO TYPE STRING,END OF T_EKKO_STR. DATA: WA_/PRA/S_BP_VENDOR_MD_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_/PRA/S_BP_VENDOR_MD_STR-SENDER_TECHNICAL_ID sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-VENDID sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-INTERCOCD sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-PARTNERROLE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-ENTY_CD sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-DIRECT_PAY_FL sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-DO_NOT_RPT_ONRR sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_MIN_PAY sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-PAY_FREQUENCY sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-DO_NOT_RECOUP sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-PAYMENT_TYPE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-NO_CHECK_STMT sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-LEVY sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-KGLND sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-CDEX_COMPANY sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-TRIBE_NO sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-BACKUP_WITHHOLD sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-KGREG sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-TAX_ID_TYPE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-RECOUP_PC sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-RECIP_CODE_1042S sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-TIN_MATCH_DATE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-TIN_RESP_DATE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-TIN_W8 sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-TIN_W9 sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-TIN_OTHERS sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-BN1_DATE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-BN1_RESP_DATE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-BN1_W8 sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-BN1_W9 sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-BN1_OTHERS sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-BN2_DATE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-IRS_RESP_DATE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-FLAG_1099 sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-FLAG_NRA sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-REP_ENTITY_TYPE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-NAME_ID sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_NM_LAST sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_NM_FIRST sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_NM_MIDDLE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_NM_PREFIX sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_NM_SUFFIX sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_NM_TITLE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_ADDRESS1 sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_ADDRESS2 sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_ADDRESS3 sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_CITY sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_COUNTY sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_STATE sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_ZIP sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_COUNTRY sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_TAXID sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_TAXID_EXT sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-OWNER_DOB sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-T_RCPMNTINFO sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-T_SPHNDLCODES sy-vline
WA_/PRA/S_BP_VENDOR_MD_STR-T_EXWHTINFO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.