ABAP Select data from SAP table CRMD_UBB_NOTIF_H 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 CRMD_UBB_NOTIF_H 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 CRMD_UBB_NOTIF_H. 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 CRMD_UBB_NOTIF_H 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_CRMD_UBB_NOTIF_H TYPE STANDARD TABLE OF CRMD_UBB_NOTIF_H,
      WA_CRMD_UBB_NOTIF_H TYPE CRMD_UBB_NOTIF_H,
      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: <CRMD_UBB_NOTIF_H> TYPE CRMD_UBB_NOTIF_H.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM CRMD_UBB_NOTIF_H
*  INTO TABLE @DATA(IT_CRMD_UBB_NOTIF_H2).
*--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_CRMD_UBB_NOTIF_H INDEX 1 INTO DATA(WA_CRMD_UBB_NOTIF_H2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_CRMD_UBB_NOTIF_H ASSIGNING <CRMD_UBB_NOTIF_H>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<CRMD_UBB_NOTIF_H>-CLIENT = 1.
<CRMD_UBB_NOTIF_H>-GUID = 1.
<CRMD_UBB_NOTIF_H>-CREATED_AT = 1.
<CRMD_UBB_NOTIF_H>-CREATED_BY = 1.
<CRMD_UBB_NOTIF_H>-CHANGED_AT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_CRMD_UBB_NOTIF_H-CHANGED_BY, sy-vline,
WA_CRMD_UBB_NOTIF_H-HEADER, sy-vline,
WA_CRMD_UBB_NOTIF_H-ITEM, sy-vline,
WA_CRMD_UBB_NOTIF_H-PARTNER_GUID, sy-vline,
WA_CRMD_UBB_NOTIF_H-REF_PARTNER_NO, sy-vline,
WA_CRMD_UBB_NOTIF_H-ADDR_NR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CRMD_UBB_NOTIF_H 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_CRMD_UBB_NOTIF_H 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_CRMD_UBB_NOTIF_H INTO WA_CRMD_UBB_NOTIF_H. *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 TSTLC, internal->external for field CREATED_AT CALL FUNCTION 'CONVERSION_EXIT_TSTLC_OUTPUT' EXPORTING input = WA_CRMD_UBB_NOTIF_H-CREATED_AT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CRMD_UBB_NOTIF_H-CREATED_AT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTLC, internal->external for field CHANGED_AT CALL FUNCTION 'CONVERSION_EXIT_TSTLC_OUTPUT' EXPORTING input = WA_CRMD_UBB_NOTIF_H-CHANGED_AT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CRMD_UBB_NOTIF_H-CHANGED_AT.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

*Conversion exit TSTPS, internal->external for field TIMESTAMP_FROM CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_CRMD_UBB_NOTIF_H-TIMESTAMP_FROM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CRMD_UBB_NOTIF_H-TIMESTAMP_FROM.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit PRID1, internal->external for field IOBJECT_ID CALL FUNCTION 'CONVERSION_EXIT_PRID1_OUTPUT' EXPORTING input = WA_CRMD_UBB_NOTIF_H-IOBJECT_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CRMD_UBB_NOTIF_H-IOBJECT_ID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field SETTL_FROM CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_CRMD_UBB_NOTIF_H-SETTL_FROM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CRMD_UBB_NOTIF_H-SETTL_FROM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field SETTL_TO CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_CRMD_UBB_NOTIF_H-SETTL_TO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CRMD_UBB_NOTIF_H-SETTL_TO.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ALPHA, internal->external for field POOL_CONTRACT_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CRMD_UBB_NOTIF_H-POOL_CONTRACT_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CRMD_UBB_NOTIF_H-POOL_CONTRACT_ID.
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_CRMD_UBB_NOTIF_H_STR,
CLIENT TYPE STRING,
GUID TYPE STRING,
CREATED_AT TYPE STRING,
CREATED_BY TYPE STRING,
CHANGED_AT TYPE STRING,
CHANGED_BY TYPE STRING,
HEADER TYPE STRING,
ITEM TYPE STRING,
PARTNER_GUID TYPE STRING,
REF_PARTNER_NO TYPE STRING,
ADDR_NR TYPE STRING,
ADDR_NP TYPE STRING,
ADDR_TYPE TYPE STRING,
ADDR_ORIGIN TYPE STRING,
STD_BP_ADDRESS TYPE STRING,
ADDR_OPERATION TYPE STRING,
ADDR_NR_SEND TYPE STRING,
ADDR_NP_SEND TYPE STRING,
PRODUCT TYPE STRING,
ORDERED_PROD TYPE STRING,
PARTNER_PROD TYPE STRING,
DATE_FROM TYPE STRING,
TIMESTAMP_FROM TYPE STRING,
TIMEZONE_FROM TYPE STRING,
IBIB_GUID TYPE STRING,
IBASE TYPE STRING,
IB_COMP_REF_GUID TYPE STRING,
IB_INSTANCE TYPE STRING,
IOBJECT_ID TYPE STRING,
SETTL_FROM TYPE STRING,
SETTL_TO TYPE STRING,
CHANNEL TYPE STRING,
OUT_MEDIA TYPE STRING,
PARTNER_FCT TYPE STRING,
FORMNAME TYPE STRING,
PROCESSED TYPE STRING,
PRO_ERROR TYPE STRING,
SEQUENCE TYPE STRING,
SEQ_ORDER TYPE STRING,
CONTRACT_ID TYPE STRING,
CONTRACT_ITEM TYPE STRING,
POOL_CONTRACT_ID TYPE STRING,
POOL_CONTRACT_IT TYPE STRING,END OF T_EKKO_STR. DATA: WA_CRMD_UBB_NOTIF_H_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_CRMD_UBB_NOTIF_H_STR-CLIENT sy-vline
WA_CRMD_UBB_NOTIF_H_STR-GUID sy-vline
WA_CRMD_UBB_NOTIF_H_STR-CREATED_AT sy-vline
WA_CRMD_UBB_NOTIF_H_STR-CREATED_BY sy-vline
WA_CRMD_UBB_NOTIF_H_STR-CHANGED_AT sy-vline
WA_CRMD_UBB_NOTIF_H_STR-CHANGED_BY sy-vline
WA_CRMD_UBB_NOTIF_H_STR-HEADER sy-vline
WA_CRMD_UBB_NOTIF_H_STR-ITEM sy-vline
WA_CRMD_UBB_NOTIF_H_STR-PARTNER_GUID sy-vline
WA_CRMD_UBB_NOTIF_H_STR-REF_PARTNER_NO sy-vline
WA_CRMD_UBB_NOTIF_H_STR-ADDR_NR sy-vline
WA_CRMD_UBB_NOTIF_H_STR-ADDR_NP sy-vline
WA_CRMD_UBB_NOTIF_H_STR-ADDR_TYPE sy-vline
WA_CRMD_UBB_NOTIF_H_STR-ADDR_ORIGIN sy-vline
WA_CRMD_UBB_NOTIF_H_STR-STD_BP_ADDRESS sy-vline
WA_CRMD_UBB_NOTIF_H_STR-ADDR_OPERATION sy-vline
WA_CRMD_UBB_NOTIF_H_STR-ADDR_NR_SEND sy-vline
WA_CRMD_UBB_NOTIF_H_STR-ADDR_NP_SEND sy-vline
WA_CRMD_UBB_NOTIF_H_STR-PRODUCT sy-vline
WA_CRMD_UBB_NOTIF_H_STR-ORDERED_PROD sy-vline
WA_CRMD_UBB_NOTIF_H_STR-PARTNER_PROD sy-vline
WA_CRMD_UBB_NOTIF_H_STR-DATE_FROM sy-vline
WA_CRMD_UBB_NOTIF_H_STR-TIMESTAMP_FROM sy-vline
WA_CRMD_UBB_NOTIF_H_STR-TIMEZONE_FROM sy-vline
WA_CRMD_UBB_NOTIF_H_STR-IBIB_GUID sy-vline
WA_CRMD_UBB_NOTIF_H_STR-IBASE sy-vline
WA_CRMD_UBB_NOTIF_H_STR-IB_COMP_REF_GUID sy-vline
WA_CRMD_UBB_NOTIF_H_STR-IB_INSTANCE sy-vline
WA_CRMD_UBB_NOTIF_H_STR-IOBJECT_ID sy-vline
WA_CRMD_UBB_NOTIF_H_STR-SETTL_FROM sy-vline
WA_CRMD_UBB_NOTIF_H_STR-SETTL_TO sy-vline
WA_CRMD_UBB_NOTIF_H_STR-CHANNEL sy-vline
WA_CRMD_UBB_NOTIF_H_STR-OUT_MEDIA sy-vline
WA_CRMD_UBB_NOTIF_H_STR-PARTNER_FCT sy-vline
WA_CRMD_UBB_NOTIF_H_STR-FORMNAME sy-vline
WA_CRMD_UBB_NOTIF_H_STR-PROCESSED sy-vline
WA_CRMD_UBB_NOTIF_H_STR-PRO_ERROR sy-vline
WA_CRMD_UBB_NOTIF_H_STR-SEQUENCE sy-vline
WA_CRMD_UBB_NOTIF_H_STR-SEQ_ORDER sy-vline
WA_CRMD_UBB_NOTIF_H_STR-CONTRACT_ID sy-vline
WA_CRMD_UBB_NOTIF_H_STR-CONTRACT_ITEM sy-vline
WA_CRMD_UBB_NOTIF_H_STR-POOL_CONTRACT_ID sy-vline
WA_CRMD_UBB_NOTIF_H_STR-POOL_CONTRACT_IT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.