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

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

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

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


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SCMB/MDL_PRS_PARTNER ASSIGNING </SCMB/MDL_PRS_PARTNER>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCMB/MDL_PRS_PARTNER>-PARTNER_GUID = 1.
</SCMB/MDL_PRS_PARTNER>-PARTNER_ROLE = 1.
</SCMB/MDL_PRS_PARTNER>-PARTNER = 1.
</SCMB/MDL_PRS_PARTNER>-TYPE = 1.
</SCMB/MDL_PRS_PARTNER>-NAME = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SCMB/MDL_PRS_PARTNER-ADDRNUMBER, sy-vline,
WA_/SCMB/MDL_PRS_PARTNER-PERSNUMBER, sy-vline,
WA_/SCMB/MDL_PRS_PARTNER-ADR, sy-vline,
WA_/SCMB/MDL_PRS_PARTNER-GLN, sy-vline,
WA_/SCMB/MDL_PRS_PARTNER-DUNS, sy-vline,
WA_/SCMB/MDL_PRS_PARTNER-SCACD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCMB/MDL_PRS_PARTNER 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_/SCMB/MDL_PRS_PARTNER 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_/SCMB/MDL_PRS_PARTNER INTO WA_/SCMB/MDL_PRS_PARTNER. *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 PARTNER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCMB/MDL_PRS_PARTNER-PARTNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/MDL_PRS_PARTNER-PARTNER.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit ISOLA, internal->external for field PRT_LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_/SCMB/MDL_PRS_PARTNER-PRT_LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/MDL_PRS_PARTNER-PRT_LANGU.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ISOLA, internal->external for field LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_/SCMB/MDL_PRS_PARTNER-LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/MDL_PRS_PARTNER-LANGU.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ISOLA, internal->external for field LANGU_CORR CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_/SCMB/MDL_PRS_PARTNER-LANGU_CORR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCMB/MDL_PRS_PARTNER-LANGU_CORR.
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_/SCMB/MDL_PRS_PARTNER_STR,
PARTNER_GUID TYPE STRING,
PARTNER_ROLE TYPE STRING,
PARTNER TYPE STRING,
TYPE TYPE STRING,
NAME TYPE STRING,
ADDRNUMBER TYPE STRING,
PERSNUMBER TYPE STRING,
ADR TYPE STRING,
GLN TYPE STRING,
DUNS TYPE STRING,
SCACD TYPE STRING,
PRT_LANGU TYPE STRING,
BID TYPE STRING,
XBLCK TYPE STRING,
XDELE TYPE STRING,
NOT_RELEASED TYPE STRING,
ROLES TYPE STRING,
TITLE TYPE STRING,
FIRST_NAME TYPE STRING,
MIDDLE_NAME TYPE STRING,
FULL_NAME TYPE STRING,
BU_USER TYPE STRING,
NAME TYPE STRING,
PWD TYPE STRING,
CLASS TYPE STRING,
STERM1 TYPE STRING,
STERM2 TYPE STRING,
ADDRCOMM TYPE STRING,
TITLE_ACA1 TYPE STRING,
TITLE_ACA2 TYPE STRING,
TITLE_SPPL TYPE STRING,
PREFIX1 TYPE STRING,
PREFIX2 TYPE STRING,
PRTDESC TYPE STRING,
ICOMM TYPE STRING,
COUNTRY TYPE STRING,
REGION TYPE STRING,
POST_CODE1 TYPE STRING,
CITY1 TYPE STRING,
STREET TYPE STRING,
HOUSE_NUM1 TYPE STRING,
TITLE TYPE STRING,
NAME1 TYPE STRING,
NAME2 TYPE STRING,
NAME3 TYPE STRING,
NAME4 TYPE STRING,
LANGU TYPE STRING,
LANGU_CORR TYPE STRING,
TEL_NUMBER TYPE STRING,
TEL_EXTENS TYPE STRING,
TELNR_LONG TYPE STRING,
TELNR_CALL TYPE STRING,
MOBTEL_NUMBER TYPE STRING,
MOBTEL_EXTENS TYPE STRING,
MOBTELNR_LONG TYPE STRING,
MOBTELNR_CALL TYPE STRING,
FAX_NUMBER TYPE STRING,
FAX_EXTENS TYPE STRING,
FAXNR_LONG TYPE STRING,
FAXNR_CALL TYPE STRING,
URI_TYPE TYPE STRING,
URI_LENGTH TYPE STRING,
URI_ADDR TYPE STRING,
SMTP_ADDR TYPE STRING,
ENCODE TYPE STRING,
TNEF TYPE STRING,
TRANSPZONE TYPE STRING,
NATION TYPE STRING,
EMPLOYEE_ID TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCMB/MDL_PRS_PARTNER_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_/SCMB/MDL_PRS_PARTNER_STR-PARTNER_GUID sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-PARTNER_ROLE sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-PARTNER sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TYPE sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-NAME sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-ADDRNUMBER sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-PERSNUMBER sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-ADR sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-GLN sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-DUNS sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-SCACD sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-PRT_LANGU sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-BID sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-XBLCK sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-XDELE sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-NOT_RELEASED sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-ROLES sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TITLE sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-FIRST_NAME sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-MIDDLE_NAME sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-FULL_NAME sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-BU_USER sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-NAME sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-PWD sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-CLASS sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-STERM1 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-STERM2 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-ADDRCOMM sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TITLE_ACA1 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TITLE_ACA2 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TITLE_SPPL sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-PREFIX1 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-PREFIX2 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-PRTDESC sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-ICOMM sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-COUNTRY sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-REGION sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-POST_CODE1 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-CITY1 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-STREET sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-HOUSE_NUM1 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TITLE sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-NAME1 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-NAME2 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-NAME3 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-NAME4 sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-LANGU sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-LANGU_CORR sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TEL_NUMBER sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TEL_EXTENS sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TELNR_LONG sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TELNR_CALL sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-MOBTEL_NUMBER sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-MOBTEL_EXTENS sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-MOBTELNR_LONG sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-MOBTELNR_CALL sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-FAX_NUMBER sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-FAX_EXTENS sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-FAXNR_LONG sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-FAXNR_CALL sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-URI_TYPE sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-URI_LENGTH sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-URI_ADDR sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-SMTP_ADDR sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-ENCODE sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TNEF sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-TRANSPZONE sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-NATION sy-vline
WA_/SCMB/MDL_PRS_PARTNER_STR-EMPLOYEE_ID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.