ABAP Select data from SAP table /DSD/ME_CUST_SA 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 /DSD/ME_CUST_SA 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 /DSD/ME_CUST_SA. 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 /DSD/ME_CUST_SA 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_/DSD/ME_CUST_SA TYPE STANDARD TABLE OF /DSD/ME_CUST_SA, WA_/DSD/ME_CUST_SA TYPE /DSD/ME_CUST_SA, 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: </DSD/ME_CUST_SA> TYPE /DSD/ME_CUST_SA. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/DSD/ME_CUST_SA. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /DSD/ME_CUST_SA INTO TABLE IT_/DSD/ME_CUST_SA. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /DSD/ME_CUST_SA * INTO TABLE @DATA(IT_/DSD/ME_CUST_SA2). *--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_/DSD/ME_CUST_SA INDEX 1 INTO DATA(WA_/DSD/ME_CUST_SA2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/DSD/ME_CUST_SA ASSIGNING </DSD/ME_CUST_SA>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</DSD/ME_CUST_SA>-CLIENT = 1.
</DSD/ME_CUST_SA>-CUST_NO = 1.
</DSD/ME_CUST_SA>-SALES_ORG = 1.
</DSD/ME_CUST_SA>-DIST_CHANNEL = 1.
</DSD/ME_CUST_SA>-DIVISION = 1.
ENDLOOP. LOOP AT IT_/DSD/ME_CUST_SA INTO WA_/DSD/ME_CUST_SA. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/DSD/ME_CUST_SA-SOLD_TO_NO, sy-vline,
WA_/DSD/ME_CUST_SA-BILL_TO_NO, sy-vline,
WA_/DSD/ME_CUST_SA-SHIP_TO_NO, sy-vline,
WA_/DSD/ME_CUST_SA-PAYER_NO, sy-vline,
WA_/DSD/ME_CUST_SA-CUSTOMER_GROUP1, sy-vline,
WA_/DSD/ME_CUST_SA-PYMT_METHOD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/DSD/ME_CUST_SA 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_/DSD/ME_CUST_SA 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_/DSD/ME_CUST_SA INTO WA_/DSD/ME_CUST_SA. *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 CUST_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/DSD/ME_CUST_SA-CUST_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/DSD/ME_CUST_SA-CUST_NO.
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_/DSD/ME_CUST_SA_STR,
CLIENT TYPE STRING,
CUST_NO TYPE STRING,
SALES_ORG TYPE STRING,
DIST_CHANNEL TYPE STRING,
DIVISION TYPE STRING,
SOLD_TO_NO TYPE STRING,
BILL_TO_NO TYPE STRING,
SHIP_TO_NO TYPE STRING,
PAYER_NO TYPE STRING,
CUSTOMER_GROUP1 TYPE STRING,
PYMT_METHOD TYPE STRING,
POD_INV TYPE STRING,
CASH_PAYER TYPE STRING,
CASH_PAYER_AF TYPE STRING,
LOEVM TYPE STRING,
PAY_CODE TYPE STRING,
EXTFLD7 TYPE STRING,
EXTFLD8 TYPE STRING,
EXTFLD9 TYPE STRING,
EXTFLD10 TYPE STRING,
PRC_LIST TYPE STRING,
PRICE_GROUP TYPE STRING,
CUSTOMER_GROUP TYPE STRING,
TAX_CAT1 TYPE STRING,
TAX_CLASS1 TYPE STRING,
TAX_CAT2 TYPE STRING,
TAX_CLASS2 TYPE STRING,
TAX_CAT3 TYPE STRING,
TAX_CLASS3 TYPE STRING,
CUSTOMER_GROUP2 TYPE STRING,
CUSTOMER_GROUP3 TYPE STRING,
CUSTOMER_GROUP4 TYPE STRING,
CUSTOMER_GROUP5 TYPE STRING,
PLANT TYPE STRING,
INVOICE_PAYER TYPE STRING,
ME_ACTION TYPE STRING,
BILL_BLOCK2 TYPE STRING,
DELV_BLOCK2 TYPE STRING,
SALE_BLOCK2 TYPE STRING,END OF T_EKKO_STR. DATA: WA_/DSD/ME_CUST_SA_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_/DSD/ME_CUST_SA_STR-CLIENT sy-vline
WA_/DSD/ME_CUST_SA_STR-CUST_NO sy-vline
WA_/DSD/ME_CUST_SA_STR-SALES_ORG sy-vline
WA_/DSD/ME_CUST_SA_STR-DIST_CHANNEL sy-vline
WA_/DSD/ME_CUST_SA_STR-DIVISION sy-vline
WA_/DSD/ME_CUST_SA_STR-SOLD_TO_NO sy-vline
WA_/DSD/ME_CUST_SA_STR-BILL_TO_NO sy-vline
WA_/DSD/ME_CUST_SA_STR-SHIP_TO_NO sy-vline
WA_/DSD/ME_CUST_SA_STR-PAYER_NO sy-vline
WA_/DSD/ME_CUST_SA_STR-CUSTOMER_GROUP1 sy-vline
WA_/DSD/ME_CUST_SA_STR-PYMT_METHOD sy-vline
WA_/DSD/ME_CUST_SA_STR-POD_INV sy-vline
WA_/DSD/ME_CUST_SA_STR-CASH_PAYER sy-vline
WA_/DSD/ME_CUST_SA_STR-CASH_PAYER_AF sy-vline
WA_/DSD/ME_CUST_SA_STR-LOEVM sy-vline
WA_/DSD/ME_CUST_SA_STR-PAY_CODE sy-vline
WA_/DSD/ME_CUST_SA_STR-EXTFLD7 sy-vline
WA_/DSD/ME_CUST_SA_STR-EXTFLD8 sy-vline
WA_/DSD/ME_CUST_SA_STR-EXTFLD9 sy-vline
WA_/DSD/ME_CUST_SA_STR-EXTFLD10 sy-vline
WA_/DSD/ME_CUST_SA_STR-PRC_LIST sy-vline
WA_/DSD/ME_CUST_SA_STR-PRICE_GROUP sy-vline
WA_/DSD/ME_CUST_SA_STR-CUSTOMER_GROUP sy-vline
WA_/DSD/ME_CUST_SA_STR-TAX_CAT1 sy-vline
WA_/DSD/ME_CUST_SA_STR-TAX_CLASS1 sy-vline
WA_/DSD/ME_CUST_SA_STR-TAX_CAT2 sy-vline
WA_/DSD/ME_CUST_SA_STR-TAX_CLASS2 sy-vline
WA_/DSD/ME_CUST_SA_STR-TAX_CAT3 sy-vline
WA_/DSD/ME_CUST_SA_STR-TAX_CLASS3 sy-vline
WA_/DSD/ME_CUST_SA_STR-CUSTOMER_GROUP2 sy-vline
WA_/DSD/ME_CUST_SA_STR-CUSTOMER_GROUP3 sy-vline
WA_/DSD/ME_CUST_SA_STR-CUSTOMER_GROUP4 sy-vline
WA_/DSD/ME_CUST_SA_STR-CUSTOMER_GROUP5 sy-vline
WA_/DSD/ME_CUST_SA_STR-PLANT sy-vline
WA_/DSD/ME_CUST_SA_STR-INVOICE_PAYER sy-vline
WA_/DSD/ME_CUST_SA_STR-ME_ACTION sy-vline
WA_/DSD/ME_CUST_SA_STR-BILL_BLOCK2 sy-vline
WA_/DSD/ME_CUST_SA_STR-DELV_BLOCK2 sy-vline
WA_/DSD/ME_CUST_SA_STR-SALE_BLOCK2 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.