Shared Top Border

Enterprise Resource
Planning Portal

 

Advertise | Founder BLOG

ERPGenie.COM ABAP Tips and Tricks Database

THE ultimate
ERP website

 

Forums | Vote for us |

Google    Other Search Options

Home arrow Tips and Tricks arrow ABAP Reports arrow EMail text using Hypertext, books and chapters
EMail text using Hypertext, books and chapters PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Anon.   
Wednesday, 28 February 2007
Step by step procedure on how to use hypertext documents, chapters and book to store text in SAP and then to retrieve it for use in an email. Why not store your email text in a chapter and if somoene wants to dynamicall y change the email output from your program then they can easily do so.

Email text Configuration

TABLE OF CONTENTS

Email text Configuration

Step 1: Book definition - (Main chapter in a structure).

Step 2: Chapter definition - (Chapter in a structure)

Step 3: Hypertext structures.

Step 4: ABAP

Initialize document

Read document

Return subject (Chapter description)

Example ABAP

FORM SEND_EMAIL2

FORM RETURN_DOKU_TEXT TABLES   L_TAB_TEXT

FORM PROTOCOL_UPDATE_V2 USING VALUE(RCODE) TYPE I

Send_email function module

FUNCTION Z_SEND_EMAIL_ITAB

Executing the send

 

Step 1: Book definition - (Main chapter in a structure)

Transaction: SO72 (Tools -> Hypertext -> Documents)

BOOKZAGILENT

The following chapters are templates to generate the required Email notifications. The variables must be specified as &FLDNAME& where FLDNAME is a global field name in that runtime environment.

This is not a SAPscript, nor has the features of the SAPscript. It was meant to be language dependant and to replace the field place holders with their corresponding value.

Step 2: Chapter definition - (Chapter in a structure)

Transaction: SO72 (Tools -> Hypertext -> Documents)

CHAPZ_AGILENT_NOTIF_1

*    This message confirms that on &MSG-ERDAT& a referral to &MSG-REFTXT& a

     &MSG-SEQ_MATNR& was &MSG-ACTVTXT& for Patient ID &MSG-PID&.           

     Installation is required on &MSG-VDATU&. Material will &MSG-STR_NOT& be

     shipped to patient.                                                   

*    'end of message'                                                        

CHAPZ_AGILENT_NOTIF_2

*    This message confirms that on &MSG-LFDAT& a &MSG-SEQ_MATNR&  was

     shipped for Patient ID &MSG-PID&.                              

*    Carrier: &MSG-ROUTE&                                           

*    Tracking #: &MSG-BOLNR&                                         

*    'end of message'

CHAPZ_AGILENT_NOTIF_3

*    This message confirms that on &MSG-LFDAT& a &MSG-SEQ_MATNR& was shipped

     for Patient ID &MSG-PID&.                                              

*    Carrier: &MSG-ROUTE&                                                    

*    Tracking #: &MSG-BOLNR&                                                

*    'end of message'                                                       

CHAPZ_AGILENT_NOTIF_4

*    This message confirms that on &MSG-ERDAT& the referral to &MSG-REFTXT&

     for Patient ID &MSG-PID& was completed. Please note UIDs below. You  

     will receive written confirmation by fax from the service provider   

     within 24 hours. Device UIDs are:                                    

*                                                                          

*    'end of message'                                                     

CHAPZ_AGILENT_NOTIF_5

*    This message confirms that on &MSG-ERDAT& a replacement &MSG-REFTXT&  

     was delivered to Patient ID &MSG-PID&. Please note the UIDs below. You

     will receive no other notice of this event. Device UIDs are:          

*                                                                          

*    'end of message'                                                       

CHAPZ_AGILENT_NOTIF_6

*    This message confirms that on &MSG-ERDAT& the ship to address for the

     &MSG-REFTXT& has been modified for Patient ID &MSG-PID&.             

*    'end of message'                                                      

CHAPZ_AGILENT_NOTIF_7

*    This message confirms that on &MSG-ERDAT& a &MSG-SEQ_MATNR& was ordered

     for delivery to &MSG-NAME1& on or before &MSG-VDATU&. Order ID is     

     &MSG-VBELN&.                                                           

*    'end of message'                                                      

Step 3: Hypertext structures

Transaction: SO70 (Tools -> Hypertext -> Structures)

ZAGILENT

Agilent Message Types                                       (ß Book definition - BOOKZAGILENT)

0  HIS System Order                           (ß Chapter definition - CHAPZ_AGILENT_NOTIF_1)

0  HIS Ship to Address Modified      (ß Chapter definition - CHAPZ_AGILENT_NOTIF_2)

0  IHS Referral completion               (ß Chapter definition - CHAPZ_AGILENT_NOTIF_3)

0  IHS Referral completion               (ß Chapter definition - CHAPZ_AGILENT_NOTIF_4)

0  IHS Shipment Confirmation        (ß Chapter definition - CHAPZ_AGILENT_NOTIF_5)

0  IHS Shipment Confirmation        (ß Chapter definition - CHAPZ_AGILENT_NOTIF_6)

0  IHS referral confirmation              (ß Chapter definition - CHAPZ_AGILENT_NOTIF_7)

Step 4: ABAP

Initialize document

CALL FUNCTION 'DOCU_INIT'  

     EXPORTING             

          ID     = ID                                                                                    (=> HY)

          LANGU  = DOKLANGU                                                          (=> E)

          OBJECT = OBJECT                                                                  (=>CHAPZ_AGILENT_NOTIF_3)

          TYP    = TYP                                                                               (=> E)

     IMPORTING             

          FOUND  = FOUND   

          XDOKIL = XDOKIL.                                                               ID                                            C      2  HY                   

OBJECT                   C     60  CHAPZ_AGILENT_NOTIF_3

LANGU                   C      1  E                     

TYP                         C      1  E                    

VERSION                N      4  0006                 

MASTERLANG       C      1  X                    

TXTLINES              N      5  00005                

DOKSTATE            C      1  R                     

SELFDEF                C      1

Read document

CALL FUNCTION 'DOCU_READ'        

     EXPORTING                   

          ID      = ID                                                                                   (=> HY)

          LANGU   = DOKLANGU                                                         (=> E)

          OBJECT  = OBJECT                                                                 (=>CHAPZ_AGILENT_NOTIF_3)

          TYP     = TYP                                                                              (=> E)

          VERSION = XDOKIL-VERSION                                          (=> XDOKIL-VERSION)

     IMPORTING                   

          HEAD    = HEADER       

     TABLES                      

          LINE    = LLINES.                                                                     (Email text)

Return subject (Chapter description)

CALL FUNCTION 'TOCX_OBJECT_TITLE'

     EXPORTING                  

          DOKCLASS = OBJECT+0(4)                                                 (=> CHAP)

          DOKLANGU = DOKLANGU                                                  (=> E)

          DOKNAME  = OBJECT+4                                                      (=>Z_AGILENT_NOTIF_3)

     IMPORTING                   

          DOKTITLE = P_SUBJECT.                                                    (Subject)

Example ABAP

FORM SEND_EMAIL2.                                                

                                                                 

*- local data declaration                                         

  DATA:                                                          

    BEGIN OF L_TAB_DEVICELIST OCCURS 0,                          

      DEVICETYPE TYPE ZAGIL_AGILENTDEVICETYPE,                   

    END   OF L_TAB_DEVICELIST,                                    

    L_DATE(10),                                                  

    L_FLAGBPECG,                                                 

    L_BOX_WBSTK,                                                 

    L_AGTSTATUS       TYPE ZAGIL_AGILENTDOCSTATUS,               

    L_AGTSTATUSTXT    TYPE ZAGIL_AGILENTDOCSTATUSTXT,            

    L_MSGTYPE(1)      TYPE N,                                    

    L_EMAILTITLE      LIKE SOOD1-OBJDES,                         

    L_RECEXTNAM       LIKE SOOS1-RECEXTNAM,                      

    L_PID             LIKE KNVK-PARAU,                           

    L_TAB_TEXT        LIKE SOLI OCCURS 0 WITH HEADER LINE,       

    L_TAB_SENDTOPARVW LIKE SENDTOPARVW  OCCURS 0 WITH HEADER LINE,

    L_TAB_SENDTO      LIKE G_TAB_SENDTO OCCURS 0 WITH HEADER LINE,

    L_LANGU           LIKE G_TAB_SENDTO-LANGU,                   

    L_SAVE_SYTABIX    LIKE SY-TABIX,                             

    L_POSNR           LIKE LIPS-POSNR.                            

                                                                 

*- init                                                          

CLEAR MSG. "communication to hypertext object (Email text)     

                                                                  

*- read SO                                                       

  SELECT SINGLE * FROM VBAK INTO VBAK                            

   WHERE VBELN = VBDKA-VBELN.                                    

                                                                  

*- read VBUK                                                     

  SELECT SINGLE * FROM VBUK INTO VBUK                            

   WHERE VBELN = VBDKA-VBELN.                                    

*  Referral type is VBAK-VKGRP                                   

*  Prior Status  is VBAK-KVGR3                                   

                                                                 

*- determine Referral Status (current)                           

  PERFORM RETURN_AGTSTATUS                                       

          USING    VBUK-LFSTK          "SO Hdr Dlv Status        

                   VBAK-LIFSK          "SO Hdr Dlv Block         

                   VBAK-VSNMR_V        "Installation date         

                   VBAK-VKGRP          "RefType                  

                   L_BOX_WBSTK         "Box Order PGI status     

          CHANGING L_AGTSTATUS         "Agilent Doc Status       

                   L_AGTSTATUSTXT.     "Agilent Doc Status Text  

  IF L_AGTSTATUS = C_QMARK.                                      

    RETCODE = 1.                                                 

    SYST-MSGID = '00'.                                           

SYST-MSGNO = '398'.                                                 

    SYST-MSGTY = 'E'.                                                  

    SYST-MSGV1 = 'Could not determine'.                                

    SYST-MSGV2 = 'Agilent Document Status for SO'.                     

    SYST-MSGV3 = VBDKA-VBELN.                                          

    PERFORM PROTOCOL_UPDATE.                                           

    EXIT.                                                              

  ENDIF.                                                                

                                                                       

*- return type of referral w/ or w/o scale/hub                         

  PERFORM RETURN_FLAG_BPECG TABLES   L_TAB_DEVICELIST                  

                            CHANGING L_FLAGBPECG.                      

                                                                       

*- return Email type KWILSON - PERFORM RETURN_EMAIL_TYPE               

  PERFORM RETURN_EMAIL_TYPE TABLES   L_TAB_SENDTOPARVW "required to send

                            USING    VBAK-VKGRP                        

                                     VBAK-KVGR3                        

                                     L_AGTSTATUS                       

                                     L_FLAGBPECG                       

                                     NAST-KAPPL                        

                            CHANGING L_MSGTYPE                         

                                     MSG-ACTVTXT.                      

  IF L_MSGTYPE = SPACE.                                                

    RETCODE = 1.                                                       

SYST-MSGID = '00'.                                            

    SYST-MSGNO = '398'.                                           

    SYST-MSGTY = 'E'.                                             

    SYST-MSGV1 = 'Could not determine'.                           

    SYST-MSGV2 = 'Agilent Message Type for SO'.                   

    SYST-MSGV3 = VBDKA-VBELN.                                     

    PERFORM PROTOCOL_UPDATE.                                      

    EXIT.                                                         

  ENDIF.                                                           

  READ TABLE L_TAB_SENDTOPARVW INDEX 1.                           

  IF SY-SUBRC <> 0.                                               

    RETCODE = 1.                                                  

    SYST-MSGID = '00'.                                             

    SYST-MSGNO = '398'.                                           

    SYST-MSGTY = 'E'.                                             

    SYST-MSGV1 = 'Could not determine required'.                  

    SYST-MSGV2 = 'Agilent message Recipients for SO'.             

    SYST-MSGV3 = VBDKA-VBELN.                                     

    PERFORM PROTOCOL_UPDATE.                                      

    EXIT.                                                         

  ENDIF.                                                          

  SORT L_TAB_SENDTOPARVW.                                         

                                                                  

*- read Contact Persons' SAP SO Hdr Partner Type, and Email address

IF    VBAK-VKGRP = C_REFTYPE_SERVER                                 

     OR VBAK-VKGRP = C_REFTYPE_PMSTEST.                               

    PERFORM RETURN_PID TABLES   L_TAB_SENDTO "Partner Type from SO    

                       USING    VBDKA-VBELN SPACE                     

                       CHANGING MSG-PID.                              

  ELSE.                                                               

    PERFORM RETURN_PID TABLES   L_TAB_SENDTO "Partner Type from SO    

                       USING    VBDKA-VBELN C_X                       

                       CHANGING MSG-PID.                              

  ENDIF.                                                              

  CHECK RETCODE = 0.                                                   

  SORT L_TAB_SENDTO.                                                  

                                                                      

* read UID                                                            

  IF L_MSGTYPE CO '45'.                                               

*   get dlv no. for SO from VBFA                                      

    IF G_DLVDOCNO IS INITIAL.                                         

      SELECT SINGLE VBELN FROM VBFA INTO G_DLVDOCNO                   

       WHERE VBELV   = VBDKA-VBELN                                    

         AND POSNV   = '000010'                                       

         AND POSNN   = '000001'                                       

         AND VBTYP_N = C_VBTYP_J.                                     

    ENDIF.                                                            

    LOOP AT REFITEM.                                                  

L_POSNR = REFITEM-POSNR / 10.                                   

      SELECT SINGLE CHARG FROM LIPS INTO REFITEM-UID                 

       WHERE VBELN = G_DLVDOCNO                                      

         AND POSNR = L_POSNR.                                        

      MODIFY REFITEM.                                                 

    ENDLOOP.                                                         

*   perform read_serialno tables refitem                             

*                         using  g_dlvdocno.                         

  ENDIF.                                                             

                                                                     

*- keep only required recipients                                     

  LOOP AT L_TAB_SENDTO.                                               

*   check: to this SO Partner we must send message                   

    READ TABLE L_TAB_SENDTOPARVW WITH KEY L_TAB_SENDTO-PARVW         

                                 BINARY SEARCH.                      

    IF SY-SUBRC <> 0.                                                 

      DELETE L_TAB_SENDTO.                                           

    ENDIF.                                                           

  ENDLOOP.                                                            

  READ TABLE L_TAB_SENDTO INDEX 1.                                   

  IF SY-SUBRC <> 0.                                                  

    RETCODE = 1.                                                     

    SYST-MSGID = '00'.                                                

    SYST-MSGNO = '398'.                                              

SYST-MSGTY = 'E'.                                              

    SYST-MSGV1 = 'Required EMail recipients missing for'.          

    SYST-MSGV2 = 'Agilent Referral SO'.                            

    SYST-MSGV3 = VBDKA-VBELN.                                      

    PERFORM PROTOCOL_UPDATE.                                       

    EXIT.                                                           

  ENDIF.                                                           

                                                                   

*- set1 communication structure for Agilent Message (langu indep.) 

  MSG-ERDAT = VBAK-ERDAT.                                           

  MSG-VDATU = VBAK-VDATU.                                          

  MSG-VBELN = VBAK-VBELN.                                          

  IF NOT ( G_DLVDOCNO IS INITIAL ).                                

    SELECT SINGLE BOLNR FROM LIKP INTO MSG-BOLNR                   

     WHERE VBELN = G_DLVDOCNO.                                     

  ENDIF.                                                           

  MSG-ROUTE = SVBPLA-ROUTE.                                        

  MSG-LFDAT = SVBPLA-LFDAT.                                        

  MSG-NAME1 = VBDKA-NAME1_WE.                                      

*- send message in communication language                          

  LOOP AT L_TAB_SENDTO.                                             

L_LANGU = L_TAB_SENDTO-LANGU.                                      

 *- collect recipients for same language                                

     IF L_RECEXTNAM IS INITIAL.                                         

       L_RECEXTNAM = L_TAB_SENDTO-EMAILADDR.                            

     ELSE.                                                              

       CONCATENATE L_RECEXTNAM ',' L_TAB_SENDTO-EMAILADDR               

              INTO L_RECEXTNAM.                                          

     ENDIF.                                                             

     AT END OF LANGU.                                                   

 *- send to collected recipients in same language                       

 *     set2 communication structure for Agilent Message (langu dependent)

       SELECT SINGLE BEZEI FROM TVGRT INTO MSG-REFTXT                   

        WHERE VKGRP = VBAK-VKGRP                                        

      AND SPRAS = L_LANGU.                                               

 *     get Email text from hypertext objects                            

       PERFORM RETURN_DOKU_TEXT TABLES   L_TAB_TEXT                     

                                USING    L_MSGTYPE L_LANGU              

                                CHANGING MSG-ESUBJECT.                  

       CHECK RETCODE = 0.